﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace WebApI0001.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {


        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public string Get()
        {


            using (var db = new Admin0001DbContext())
            {
                var list = db.ProDucks.Include(x => x.Brand).Include(x => x.Category).ToList();
                //序列化
                return JsonConvert.SerializeObject(list, Formatting.Indented,
                 new JsonSerializerSettings()//處理循環應用問題jsonserializesettings
                 {
                     ReferenceLoopHandling = ReferenceLoopHandling.Ignore//設置不處理循環引用
                 }

               );

            }


        }
    }
}
